const url = 'http://localhost:8080'
import axios from "axios"
//请求数据
export const fetchAllData = async (keyword) => {
  let data;
  if (keyword) {
    data = await axios.get(`${url}/book?keyword=${keyword}`)
  }
  else {
    data = await axios.get(`${url}/book`)

  }
  return data.data
}
//请求单个数据
export const fetchSingleData = async (id) => {
  let data = await axios.get(`${url}/book/${id}`)
  return data.data
}
//新增数据
export const fetchAddDate = async (v1, v2, v3) => {
  await axios.post(`${url}/book`, { bookName: v1, author: v2, price: v3 })
}

//修改数据
export const fetchEditData = async (id, v1, v2, v3) => {
  await axios.put(`${url}/book/${id}`, { bookName: v1, author: v2, price: v3 })
}

//删除数据
export const fetchDelData = async (id) => {
  await axios.delete(`${url}/book/${id}`)
}